package com.study.spmongodb.wwj.thread.char06;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/6 10:51
 */
public class ThreadCloseGracaeful2 {
    private static class Worker extends Thread {

        @Override
        public void run() {
            while (true) {
                if (Thread.interrupted()) {
                    break;
                }
                /*try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;//return
                }*/
            }
        }

    }

    public static void main(String[] args) throws InterruptedException {
        final Worker worker = new Worker();
        worker.start();
        Thread.sleep(1000);
        worker.interrupt();
    }
}
